package cn.me.alphamq.nameserver.enumeration;

/**
 * 复制架构中节点扮演的角色的枚举类
 *
 * @author f
 */
public enum ReplicationRoleEnum {
    MASTER("master", "主从-主节点"),
    SLAVE("slave", "主从-从节点"),

    NODE("node", "链式-非尾节点"),
    TAIL("tail", "链式-尾节点");

    // 根据枚举的 code 属性获取枚举
    public static ReplicationRoleEnum of(String code) {
        for (ReplicationRoleEnum role : ReplicationRoleEnum.values()) {
            if (role.code.equals(code)) {
                return role;
            }
        }
        throw new RuntimeException("invalid replication role code: " + code);
    }

    private final String code;
    private final String desc;

    ReplicationRoleEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }
}
